package com.yuzhyn.hiops.common.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yuzhyn.azylee.websdk.model.users.UserInfo;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@TableName("sys_user")
public class SysUser {

    @TableId("id")
    private String id;

    @TableField("name")
    private String name;

    private String realName;

    private String avatar;

    private String email;

    private LocalDateTime createTime;

    private LocalDateTime updateTime;

    private Boolean isFrozen;

    private String password;

    public static SysUser fromUserInfo(UserInfo user) {
        if (user == null) {
            return null;
        }
        SysUser sysUser = new SysUser();
        sysUser.setId(user.getId());
        sysUser.setName(user.getName());
        sysUser.setRealName(user.getRealName());
        sysUser.setAvatar(user.getAvatar());
        sysUser.setEmail(user.getEmail());
        sysUser.setCreateTime(user.getCreateTime());
        sysUser.setUpdateTime(user.getUpdateTime());
        sysUser.setIsFrozen(user.getFrozen());
        sysUser.setPassword(user.getPassword());
        return sysUser;
    }

    public UserInfo toUserInfo() {
        UserInfo sysUser = new UserInfo();
        sysUser.setId(this.getId());
        sysUser.setName(this.getName());
        sysUser.setRealName(this.getRealName());
        sysUser.setAvatar(this.getAvatar());
        sysUser.setEmail(this.getEmail());
        sysUser.setCreateTime(this.getCreateTime());
        sysUser.setUpdateTime(this.getUpdateTime());
        sysUser.setFrozen(this.getIsFrozen());
        sysUser.setPassword(this.getPassword());
        return sysUser;
    }
}
